package com.atguigu.guli.service.edu.service.impl;

import com.atguigu.guli.service.edu.entity.Teacher;
import com.atguigu.guli.service.edu.entity.TeacherQuery;
import com.atguigu.guli.service.edu.mapper.TeacherMapper;
import com.atguigu.guli.service.edu.service.TeacherService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author yz
 * @since 2022-07-18
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {


    @Override
    public Page<Teacher> getPage(Page<Teacher> page, TeacherQuery teacherQuery) {
        LambdaQueryWrapper<Teacher> queryWrapper = new LambdaQueryWrapper<>();
        //获取查询条件
        String name = teacherQuery.getName();
        Integer level = teacherQuery.getLevel();
        String joinDateBegin = teacherQuery.getJoinDateBegin();
        String joinDateEnd = teacherQuery.getJoinDateEnd();

        if (!StringUtils.isEmpty(name)){
            queryWrapper.like(Teacher::getName,name);
        }
        if (level!=null){
            queryWrapper.eq(Teacher::getLevel,level);
        }
        if(!StringUtils.isEmpty(joinDateBegin)){
            queryWrapper.le(Teacher::getJoinDate ,joinDateBegin );
        }
        if(!StringUtils.isEmpty(joinDateEnd)){
            queryWrapper.le(Teacher::getJoinDate ,joinDateEnd );
        }
        //带条件的分页查询
        this.page(page , queryWrapper);
        return page;
    }

}
